<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * @author duongbq
 * Date 2011 - 05 -11
 */
class Image_Model extends CI_Model
{
    public function __construct() {
        parent::__construct();
    }
    
    /**
     * @author duongbq
     * @param type $params
     * @return type 
     */
    function get_image($params = array())
    {
        //Where_______________________________________
        
        if(isset ($params['id']))
            $this->db->where('image.id', $params['id']);
        
        if(isset ($params['img_name']))
            $this->db->where('image.img_name', $params['img_name']);
        
        if(isset ($params['order_by']))
            $this->db->order_by($params['order_by']);
        else
            $this->db->order_by('img_name');
            
        return $this->db->get('image')->result();        
    }
    
    function get_image_array($params = array())
    {
        $images = $this->get_image($params);
        $output = array();
        foreach($images as $item)
        {
            $output[$item->id] = $item->img_name;
        }
        return $output;
    }
    
    function add_image($data = array()) {
        $this->db->insert('image', $data);
        return $this->db->insert_id();
    }
    
    function delete_image($options = array()) {
        if (isset($options['id'])) {
            $this->db->where('image.id', $options['id']);
            $this->db->delete('image');
        }
    }
    
}
